//
//  ViewController.swift
//  DatePickerView
//
//  Created by 蓓蕾 on 2022/3/22.
//

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        print("开始了")
        initUI()
    }

    private func initUI(){
        
        
        
        
        
        
//        let datePickerView = YYDatePickerView()
//        self.view .addSubview(datePickerView)
        
//        YYDateTimePickerView.showDatePicker(mode: .YYDatePickerModeYMD, title: "选择时间", selectValue: nil) { date, selectValue in
//            print("date = \(date)")
//            print("selectValue = \(selectValue)")
//        }
//        getWindow().addSubview(bgView)
        
        
//        let datePickerView = YYDateTimePickerView()
//        self.view .addSubview(datePickerView)
//        datePickerView.snp.makeConstraints { make in
//            make.leading.trailing.equalToSuperview()
//            make.bottom.equalToSuperview()
//            make.height.equalTo(300)
//        }
//
//        datePickerView.CancelReturnBlock = {
//            print("点击了取消")
//        }
//
//        datePickerView.SuccessReturnBlock = { item in
//            print("选择了：\(item)")
//        }
    }
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        
        //MARK: 字符串选择器
        //     ================   1   ================
//        YYStringPickerView.showPicker(mode: .YYStringPickerComponentSingle, title: nil, dataArr: ["你猜我是谁","你猜我猜不猜","不猜"], selectIndex: 2) { resultModel in
//            print("selectString = \(String(describing: resultModel.value))")
//        }
        //     ================   2   ================
//        let one = YYResultModel()
//        one.key = "001"
//        one.value = "男"
//        one.index = 0
//
//        let two = YYResultModel()
//        two.key = "002"
//        two.value = "女"
//        two.index = 1
//
//        let three = YYResultModel()
//        three.key = "003"
//        three.value = "不限"
//        three.index = 2
        //     ================   2-1   ================
//        YYStringPickerView.showPicker(mode: .YYStringPickerComponentSingle, title: nil, dataArr: [one,two,three], selectIndex: 1) { resultModel in
//            print("selectString = \(String(describing: resultModel.value))")
//        }
        //     ================   2-2   ================
//        YYStringPickerView.showPicker(mode: .YYStringPickerComponentSingle, title: nil, dataArr: [one, two, three], selectString: "女") { resultModel in
//            print("selectString = \(String(describing: resultModel.value))")
//        }
        
        //MARK: 多列字符串
//        YYStringPickerView.showMulPicker(mode: .YYStringPickerComponentMulti, title: "多列选择器", dataArr: [["语文语文语文语文语文语文语文语文语文", "数学语文语文语文语文语文语文语文语文语文", "英语语文语文语文语文语文语文语文语文语文", "物理语文语文语文语文语文语文语文语文语文", "化学语文语文语文语文语文语文语文语文语文", "生物语文语文语文语文语文语文语文语文语文"], ["优秀语文语文语文语文语文语文语文语文语文", "良好语文语文语文语文语文语文语文语文语文", "及格语文语文语文语文语文语文语文语文语文", "不及格语文语文语文语文语文语文语文语文语文"]], selectIndex: 0) { resultArr, resultDic in
//            print("resultArr = \(resultArr)")
//            print("resultDic = \(resultDic)")
//        }
        let mathModel:YYResultModel = YYResultModel()
        mathModel.value = "数学"
        let biologyModel:YYResultModel = YYResultModel()
        biologyModel.value = "生物"
        let passModel:YYResultModel = YYResultModel()
        passModel.value = "及格"
        
//        YYStringPickerView.showMulPicker(mode: .YYStringPickerComponentMulti, title: "多列选择器", dataArr: [["语文", mathModel, "英语", "物理", "化学", biologyModel], ["优秀", "良好", passModel, "不及格"], ["123"]], selectIndexArr: ["3"]) { resultArr, resultDic in
//            print("resultArr = \(resultArr)")
//            print("resultDic = \(resultDic)")
//        }
        
//        YYStringPickerView.showMulPicker(mode: .YYStringPickerComponentMulti, title: "多列选择器", dataArr: [["语文", mathModel, "英语", "物理", "化学", biologyModel], ["优秀", "良好", passModel, "不及格"]], selectItemArr: [biologyModel,"良好"]) { resultArr, resultDic in
//            print("resultArr = \(resultArr)")
//            print("resultDic = \(resultDic)")
//        }
        
//        YYStringPickerView.showMulPicker(mode: .YYStringPickerComponentMulti, title: "多列选择器", dataArr: [["亚洲", "非洲", "北美洲", "南美洲"],["中国", "日本", "美国", "俄国", "德国"], ["扬州","杭州", "苏州", "郑州"], ["小学","初中", "高中", "大学"], ["一年级", "二年级", "三年级", "四年级", "五年级", "六年级"], ["语文", "数学", "英语", "物理", "化学", "生物"], ["优秀", "良好", "及格", "不及格"]], selectIndex: 0) { resultArr, resultDic in
//            print("resultArr = \(resultArr)")
//            print("resultDic = \(resultDic)")
//        }
        
//        ConversionBox.stringConversionToArr()
        
//        let filePath:String = Bundle.main.path(forResource: "stages.json", ofType: nil)!
//        let dataString:String = try! String(contentsOfFile: filePath, encoding: String.Encoding.utf8)
//        let dataDic = YYAddressPickerView.changeJsonToDictionary(dataString)
//        let stageInfoArr:NSArray = dataDic!["GetStageInfoDto"] as! NSArray
//        let resultArr:NSMutableArray = NSMutableArray()
//
//        for i in 0..<stageInfoArr.count {
//            let itemDic:NSDictionary = stageInfoArr[i] as! NSDictionary
//            let model = YYResultModel()
//            model.sunDataArr = itemDic["GetGradeInfoDto"] as? NSArray
//            model.sunDataArrKey = "GetGradeInfoDto"
//            model.sunDataValueKey = "Name"
//            model.value = itemDic["Name"] as? String
//            resultArr.add(model)
//        }
        
        
//        YYLog("dataArr = \(dataArr)")
//        YYStringPickerView.showMulPicker(column: 2, title: "多列联动选择器", dataArr: resultArr, selectIndexArr: nil) { resultArr, resultDic in
//
//        }
        
        
        //MARK: 地址选择器
        //     ================   1   ================
        YYAddressPickerView.showAddressPicker(mode: .YYAddressPickerModeArea, title: "", selectValue: "") { provinceModel, cityModel, areaModel in
            print("province = \(String(describing: provinceModel.name))")
            print("city = \(String(describing: cityModel.name))")
            print("area = \(String(describing: areaModel.name))")
        }
//        YYAddressPickerView.shared.maxWidth = 100
//        YYAddressPickerView.showAddressPicker(mode: .YYAddressPickerModeCity, title: "", selectValue: "") { provinceModel, cityModel, areaModel in
//            print("province = \(String(describing: provinceModel.name))")
//            print("city = \(String(describing: cityModel.name))")
//            print("area = \(String(describing: areaModel.name))")
//        }
        
//        YYAddressPickerView.showAddressPicker(mode: .YYAddressPickerModeProvince, title: "", selectValue: "") { provinceModel, cityModel, areaModel in
//            print("province = \(String(describing: provinceModel.name))")
//            print("city = \(String(describing: cityModel.name))")
//            print("area = \(String(describing: areaModel.name))")
//        }
        
        
        //MARK: 日期选择器
        YYDateTimePickerView.shared.showUnitType = .YYShowUnitTypeNone
        //     ================   3   ================
//        YYDateTimePickerView .showDatePicker(mode: .YYDatePickerModeYMDHMS, title: nil, selectValue: "1993-02-11 15:16:36") { date, value in
//            print("date = \(date)")
//            print("value = \(value)")
//        }
        
//        YYDateTimePickerView.showDatePicker(datePickerMode: .YYDatePickerModeDate, unitType: .YYShowUnitTypeNone, title: "选择出生日期", selectValue: nil) { date, value in
//            print(date)
//            print(value)
//        }
        
        //     ================   3   ================
//        YYDateTimePickerView .showDatePicker(mode: .YYDatePickerModeYMDHM, title: nil, selectValue: "1993-02-11 15:16:36") { date, value in
//            print("date = \(date)")
//            print("value = \(value)")
//        }
        
        //     ================   4   ================
//        YYDateTimePickerView .showDatePicker(mode: .YYDatePickerModeYMDH, title: nil, selectValue: "") { date, value in
//            print("date = \(date)")
//            print("value = \(value)")
//        }
        //     ================   1   ================
//        YYDateTimePickerView .showDatePicker(mode: .YYDatePickerModeMDHM, title: "", selectValue: "02-12 15:16") { date, value in
//            print("date = \(date)")
//            print("value = \(value)")
//        }
        
        //     ================   2   ================
//        YYDateTimePickerView .showDatePicker(mode: .YYDatePickerModeYMD, title: "", selectValue: "02-12") { date, value in
//            print("date = \(date)")
//            print("value = \(value)")
//        }
        
        //     ================   2   ================
//        YYDateTimePickerView .showDatePicker(mode: .YYDatePickerModeYM, title: "", selectValue: "") { date, value in
//            print("date = \(date)")
//            print("value = \(value)")
//        }
        
        //     ================   2   ================
//        YYDateTimePickerView .showDatePicker(mode: .YYDatePickerModeY, title: "", selectValue: "02-12") { date, value in
//            print("date = \(date)")
//            print("value = \(value)")
//        }
        
        //     ================   2   ================
//        YYDateTimePickerView .showDatePicker(mode: .YYDatePickerModeMD, title: "", selectValue: "02-12") { date, value in
//            print("date = \(date)")
//            print("value = \(value)")
//        }
        
//        YYDateTimePickerView .showDatePicker(mode: .YYDatePickerModeHMS, title: nil, selectValue: "") { date, value in
//            print("date = \(date)")
//            print("value = \(value)")
//        }
        
//        YYDateTimePickerView .showDatePicker(mode: .YYDatePickerModeHM, title: nil, selectValue: "") { date, value in
//            print("date = \(date)")
//            print("value = \(value)")
//        }
        
//        YYDateTimePickerView .showDatePicker(mode: .YYDatePickerModeMS, title: nil, selectValue: "") { date, value in
//            print("date = \(date)")
//            print("value = \(value)")
//        }
    }
    
    private func getWindow() ->UIWindow {
        
        
        if let window:UIWindow = (UIApplication.shared.delegate?.window)! {
            print("在 第一个 if 中获取")
            return window
        }else{
            if #available(iOS 13.0, *) {
                let array:Set = UIApplication.shared.connectedScenes
                let windowScene:UIWindowScene = array.first as! UIWindowScene
                print("IOS 13及其以上系统")
                //如果是普通App开发，可以使用
                //            SceneDelegate * delegate = (SceneDelegate *)windowScene.delegate;
                //            UIWindow * mainWindow = delegate.window;
                
                if let mainWindow:UIWindow = windowScene.value(forKeyPath:"delegate.window") as? UIWindow{
                    print("在 if 中获取")
                    return mainWindow
                }else{
                    print("在 else 中获取")
                    return UIApplication.shared.windows.first!
                }
            }else{
                print("在 最后一个 else 中获取")
                return UIApplication.shared.keyWindow!
            }
        }
    }

}

